<template>
    <div>
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="文章标题">
                <el-input v-model="form.title"></el-input>
            </el-form-item>
            <el-form-item label="文章摘要">
                <el-input type="textarea" v-model="form.summary"></el-input>
            </el-form-item>
            <el-form-item label="封面图片">
                <el-upload
                  class="avatar-uploader"
                  name="files2"
                  :action="uploadPath"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess">
                  <img id="img" v-show="form.show" :src="form.imgPath" class="avater">
                  <i v-show="!form.show" class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>  
            </el-form-item>
            <el-form-item label="文章内容">
                <wangeditor :editorHtml="form.mainBody" @getEditorCon="getEditorForm"></wangeditor>
            </el-form-item>
            <el-form-item label="状态">
                <el-select v-model="form.status" placeholder="请选择">
                    <el-option
                      v-for="item in form.status"
                      :key="item.id"
                      :label="item.label"
                      :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import wangeditor from '@/components/wangEditor/index.vue'
export default {
  components: {
    wangeditor
  },
  props: {
    form: Object
  },
  data() {
    return {
      uploadPath: '/api/file/uploadImg'
    }
  },
  methods: {
    getEditorForm(data) {
      this.$emit('getEditorData', data)
    },
    handleAvatarSuccess(res, file) {
      if (res.code === 0) {
        this.$emit('getImgPath', res.content)
      }
    }
  }
}
</script>

<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
  #img {
    width: 178px;
    height: 178px;
    overflow: hidden;
  }
</style>
